﻿using System;
using System.Collections;
using Resoure.Script.Utilities;
using Utilities;
using UnityEngine;
using EventHandler = Utilities.EventHandler;



public class WeatherManager: MonoBehaviour
{
    [Header("天气时长设定")]
    public float rainTime = 15f;
    public float windTime = 15f;
    [Header("全局灯光")] 
    public Light lights;
    [Header("粒子系统")]
    public ParticleSystem rainParticle;
    public ParticleSystem windyParticle;
    public ParticleSystem sunParticle;
    public ParticleSystem coinParticle;
    public ParticleSystem foodParticle;
    public ParticleSystem godParticle;
    public ParticleSystem healingParticle;
    public ParticleSystem technologyParticle;
    public ParticleSystem playParticle;

    private Coroutine sunCoroutine;
    private Coroutine godCoroutine;
    public void OnEnable()
    {
        EventHandler.OnWeatherActivate += ActivateWeather;
    }
    /// <summary>
    /// 开启计时器
    /// </summary>
    /// <param name="weatherType"></param>
    public void ActivateWeather(MiniPeopleEventType weatherType)
    {
        switch (weatherType)
        {
            case MiniPeopleEventType.NeedRain01:
            case MiniPeopleEventType.NeedRain02:
            case MiniPeopleEventType.NeedRain03:
                Debug.Log("下雨了");
                StartCoroutine(TimerCounter(rainTime, rainParticle));
                break;
            case MiniPeopleEventType.NeedWind01: 
            case MiniPeopleEventType.NeedWind02: 
            case MiniPeopleEventType.NeedWind03: 
                Debug.Log("刮风了");
                // TODO 调用刮风效果/视觉表现
                StartCoroutine(TimerCounter(windTime, windyParticle));
                break;
            case MiniPeopleEventType.NeedSun01:
            case MiniPeopleEventType.NeedSun02:
            case MiniPeopleEventType.NeedSun03:
                Debug.Log("出太阳了");
               
                break;
            case MiniPeopleEventType.NeedCoin01:
            case MiniPeopleEventType.NeedCoin02:
            case MiniPeopleEventType.NeedCoin03:
                StartCoroutine(TimerCounter(rainTime, coinParticle));
                // TODO 金钱粒子/视觉表现
                break;
            case MiniPeopleEventType.NeedFood01:
            case MiniPeopleEventType.NeedFood02:
            case MiniPeopleEventType.NeedFood03:
                StartCoroutine(TimerCounter(rainTime, foodParticle));
                break;
            case MiniPeopleEventType.NeedGod01:
            case MiniPeopleEventType.NeedGod02:
            case MiniPeopleEventType.NeedGod03:
              
                break;
            case MiniPeopleEventType.NeedHealing01:
            case MiniPeopleEventType.NeedHealing02:
            case MiniPeopleEventType.NeedHealing03:
                StartCoroutine(TimerCounter(rainTime, healingParticle));
                break;
            case MiniPeopleEventType.NeedPlay01:
            case MiniPeopleEventType.NeedPlay02:
            case MiniPeopleEventType.NeedPlay03:
                StartCoroutine(TimerCounter(rainTime, playParticle));
                break;
            case MiniPeopleEventType.NeedTechnology01:
            case MiniPeopleEventType.NeedTechnology02:
            case MiniPeopleEventType.NeedTechnology03:
                StartCoroutine(TimerCounter(rainTime, technologyParticle));
                break;
            default:
               Debug.Log("调用了不存在的天气");
               break;
        }
    }

    IEnumerator TimerCounter(float sec,ParticleSystem particle)
    {
        particle.Play();
        yield return new WaitForSeconds(sec);
        particle.Stop();
    }
}